package vis.items.ds.stack;

import java.awt.Color;

import processing.core.PApplet;
import vis.app.utils.Utils;
import vis.items.visualItem.IVisualObject;
import vis.items.visualItem.MyLabel;

public class StackElem extends MyLabel {
	public static int ELEM_SIZE = 80;

	public String value;
	private int limitY;
	private int limitX;
	private boolean isPoped = false;

	public StackElem(PApplet root, IVisualObject parent, String value, int index) {
		super(root, parent);
		setInfo(value);
		setLimitY(index);
		System.out.println(this.toString());
	}

	private void setInfo(String value) {
		this.value = value;
		Color bgColor = Utils.randomColor();
		this.size(ELEM_SIZE, ELEM_SIZE).color(Utils.randomHardColor());
		Color textColor = Color.white;// Utils.inverse(bgColor);
		this.text(value).textPosition(0, 0).textColor(textColor);
	}

	private void setLimitY(int index) {
		// this.index = index;
		this.limitY = (Stack.STACK_SIZE - 1 - index) * ELEM_SIZE + Stack.TOP_MARGIN;
		System.out.println("limitY: " + limitY);
	}

	public IVisualObject getParent() {
		return parent;
	}

	public void visualPopElement() {
		isPoped = true;
		this.limitX = 1000;
	}

	@Override
	public void updateItself() {
		super.updateItself();
		if (limitY > 0) {
			y += 2;
			limitY -= 2;
		}
		if (isPoped && x < limitX) {
			x += 2;
		}
	}
}
